package com.sniff.atp.service.check;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.sniff.atp.dto.ClientLoginDTO;
import com.sniff.atp.dto.order.CustomerPlatformOrderItemRespDTO;
import com.sniff.atp.dto.order.GetPlatformOrderDetailRespDTO;
import com.sniff.atp.enums.api.OrderAPI;
import com.sniff.atp.enums.status.*;
import com.sniff.atp.service.order.OrderService;
import com.sniff.atp.service.settlement.SettlementService;
import com.sniff.atp.utils.*;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.testng.Assert;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @BelongsProject: sniff-atp
 * @BelongsPackage: com.sniff.atp.service.order
 * @Author: zxy
 * @CreateTime: 2022-11-02 11:32
 * @Description: 校验订单数据
 * @Version: 1.0
 */
@Service
public class AssertedOrderService {

    private static final String MSG = "输入的操作节点不存在，node：";

    @Autowired
    private OrderService orderService;
    @Autowired
    private SettlementService settlementService;

    /**
     * 校验订单冻结金额
     *
     * @param clientLoginDTO
     * @param platformOrderNo
     * @return
     */
    public String orderAmountAssert(ClientLoginDTO clientLoginDTO, String platformOrderNo, OrderFlowType orderFlowType) {
        return orderService.clientOrderDetailAssert(clientLoginDTO, platformOrderNo, orderFlowType);
    }

    /**
     * 采购手续费校验
     */
    public void orderPurchaseAmountAssert(ClientLoginDTO clientLoginDTO, String platformOrderNo, OrderFlowType orderFlowType) {

        // 获取订单详情数据
        String result = orderService.clientOrderDetail(clientLoginDTO, platformOrderNo);
        JSONArray platformOrderItemList = JsonUtil.extractJSONArray(result, "data.platformOrderItemList");

        // 获取流水数据
        String queryFundFlow = settlementService.queryFundFlow(clientLoginDTO, platformOrderNo);
        JSONArray queryFundFlowArray = JsonUtil.extractJSONArray(queryFundFlow, "data.records");

        // 校验采购手续费
        if (orderFlowType.getFundFlowType() == 6) {
            assertPurchase(platformOrderItemList, queryFundFlowArray);
        }
        // 校验国内运费
        if (orderFlowType.getFundFlowType() == 4) {

            for (int i = 0; i < platformOrderItemList.size(); i++) {
                JSONObject jsonObject = platformOrderItemList.getJSONObject(i);
                Integer channel = jsonObject.getInteger("channel");

                // 判断商品：2 透明购，1 市场购, null oem
                if (2 == channel) {
                    BigDecimal domesticShipping = jsonObject.getBigDecimal("domesticShipping");

                    // 获取透明购国内运费配置
                    BigDecimal cost = new BigDecimal(AdditionConfig.CLEAR_D2C.getCost());
                    BigDecimal expectAmount = new BigDecimal("10.00").multiply(cost);

                    //断言订单详情透明购国内运费
                    Assert.assertEquals(expectAmount, domesticShipping);

                    for (int j = 0; j < queryFundFlowArray.size(); j++) {
                        JSONObject jsonObject1 = queryFundFlowArray.getJSONObject(j);
                        Integer fundFlowType = jsonObject1.getInteger("fundFlowType");
                        if (fundFlowType == OrderFlowType.fund_flow_type_four.getFundFlowType()) {
                            BigDecimal changeAmount = jsonObject1.getBigDecimal("changeAmount");

                            //断言资金流水市场购手续费
                            Assert.assertEquals(expectAmount, changeAmount);
                        }
                    }
                }
                if (1 == channel) {
                    BigDecimal purchasingFee = jsonObject.getBigDecimal("purchasingFee");
                    BigDecimal sellQuantity = jsonObject.getBigDecimal("sellQuantity");
                    // 获取市场购采购手续费配置
                    BigDecimal cost = new BigDecimal(AdditionConfig.MARKET_D2C.getCost());
                    BigDecimal expectAmount = sellQuantity.multiply(cost);

                    //断言订单详情市场购手续费
                    Assert.assertEquals(expectAmount, purchasingFee);

                    for (int j = 0; j < queryFundFlowArray.size(); j++) {
                        JSONObject jsonObject1 = queryFundFlowArray.getJSONObject(j);
                        String fundFlowNameCustomer = jsonObject1.getString("fundFlowNameCustomer");
                        if (fundFlowNameCustomer.equals(OrderFlowType.fund_flow_type_six.getFundFlowNameCustomer())) {
                            BigDecimal changeAmount = jsonObject1.getBigDecimal("changeAmount");

                            //断言资金流水市场购手续费
                            Assert.assertEquals(expectAmount, changeAmount);
                        }
                    }
                }
                if (channel == null) {
                    LogUtil.info("OEM采购手续校验！！！！！！！！！！");
                }
            }
        }

    }

    /**
     * 校验采购手续费
     *
     * @param platformOrderItemList
     * @param queryFundFlowArray
     */
    private void assertPurchase(JSONArray platformOrderItemList, JSONArray queryFundFlowArray) {
        for (int i = 0; i < platformOrderItemList.size(); i++) {
            JSONObject jsonObject = platformOrderItemList.getJSONObject(i);
            Integer channel = jsonObject.getInteger("channel");
            // 判断商品：2 透明购，1 市场购, null oem
            if (2 == channel) {
                BigDecimal purchasingFee = jsonObject.getBigDecimal("purchasingFee");
                BigDecimal sellQuantity = jsonObject.getBigDecimal("sellQuantity");
                // 获取透明购采购手续费配置
                BigDecimal cost = new BigDecimal(AdditionConfig.CLEAR_D2C.getCost());
                BigDecimal expectAmount = sellQuantity.multiply(cost);

                //断言订单详情透明购手续费
                Assert.assertEquals(expectAmount, purchasingFee);

                for (int j = 0; j < queryFundFlowArray.size(); j++) {
                    JSONObject jsonObject1 = queryFundFlowArray.getJSONObject(j);
                    String fundFlowNameCustomer = jsonObject1.getString("fundFlowNameCustomer");
                    if (fundFlowNameCustomer.equals(OrderFlowType.fund_flow_type_six1.getFundFlowNameCustomer())) {
                        BigDecimal changeAmount = jsonObject1.getBigDecimal("changeAmount");

                        //断言资金流水市场购手续费
                        Assert.assertEquals(expectAmount, changeAmount);
                    }
                }
            }
            if (1 == channel) {
                BigDecimal purchasingFee = jsonObject.getBigDecimal("purchasingFee");
                BigDecimal sellQuantity = jsonObject.getBigDecimal("sellQuantity");
                // 获取市场购采购手续费配置
                BigDecimal cost = new BigDecimal(AdditionConfig.MARKET_D2C.getCost());
                BigDecimal expectAmount = sellQuantity.multiply(cost);

                //断言订单详情市场购手续费
                Assert.assertEquals(expectAmount, purchasingFee);

                for (int j = 0; j < queryFundFlowArray.size(); j++) {
                    JSONObject jsonObject1 = queryFundFlowArray.getJSONObject(j);
                    String fundFlowNameCustomer = jsonObject1.getString("fundFlowNameCustomer");
                    if (fundFlowNameCustomer.equals(OrderFlowType.fund_flow_type_six.getFundFlowNameCustomer())) {
                        BigDecimal changeAmount = jsonObject1.getBigDecimal("changeAmount");

                        //断言资金流水市场购手续费
                        Assert.assertEquals(expectAmount, changeAmount);
                    }
                }
            }
            if (channel == null) {
                LogUtil.info("OEM采购手续校验！！！！！！！！！！");
            }
        }
    }

    /**
     * 订单状态校验，如果不传productSku,校验所有商品，如果传入productSku，校验指定商品的状态
     */
    public void orderProductStatusCheck(ClientLoginDTO clientLoginDTO, String platformOrderNo, OrderOperateStatus operateStatus, String productSku) {
        int count = 0;
        int countTry = 3;
        while (count < countTry) {
            try {
                ToolsUtil.sleep(5000);
                checkProductStatus(clientLoginDTO, platformOrderNo, productSku, operateStatus);
                break;
            } catch (Exception e) {
                count++;
                if (count == countTry) {
                    throw e;
                }
            }
        }
    }

    private void checkProductStatus(ClientLoginDTO clientLoginDTO, String platformOrderNo, String productSku, OrderOperateStatus operateStatus) {
        String orderDetail = orderService.clientOrderDetail(clientLoginDTO, platformOrderNo);
        GetPlatformOrderDetailRespDTO platformOrderDetail = FastUtil.toBean(JsonUtil.extractJSONObject(orderDetail, "data"), GetPlatformOrderDetailRespDTO.class);
        List<CustomerPlatformOrderItemRespDTO> platformOrderItemList = platformOrderDetail.getPlatformOrderItemList();
        Boolean normalStock = platformOrderItemList.stream()
                .anyMatch(orderItem -> orderItem.getProductType().equals(ProductType.NORMAL.getType()) && orderItem.getSellQuantity() == 0);
        Boolean normal = platformOrderItemList.stream()
                .anyMatch(orderItem -> orderItem.getProductType().equals(ProductType.NORMAL.getType()));
        if (StringUtils.isNotEmpty(productSku)) {
            CustomerPlatformOrderItemRespDTO platformOrderItemRespDTO = platformOrderItemList.stream()
                    .filter(orderItem -> orderItem.getProductSku().equals(productSku)).findAny().orElse(null);
            checkProduct(platformOrderItemRespDTO, operateStatus, normal, normalStock);
        } else {
            platformOrderItemList.forEach(orderItem -> checkProduct(orderItem, operateStatus, normal, normalStock));
        }
    }

    private void checkProduct(CustomerPlatformOrderItemRespDTO orderItem, OrderOperateStatus operateStatus, Boolean normal, Boolean normalStock) {
        // order finish
        orderFinishCheck(orderItem, operateStatus, normal, normalStock);
        // allot_finish
        orderOperateStatusCheck(orderItem, operateStatus, OrderOperateStatus.stock_allot_finish);
        deliverOrderOperateStatusCheck(orderItem, operateStatus, OrderOperateStatus.deliver_allot_finish, normalStock);
        // purchase_finish
        orderOperateStatusCheck(orderItem, operateStatus, OrderOperateStatus.stock_purchase_finish);
        deliverOrderOperateStatusCheck(orderItem, operateStatus, OrderOperateStatus.deliver_purchase_finish, normalStock);
        // checkout_finish
        orderOperateStatusCheck(orderItem, operateStatus, OrderOperateStatus.stock_checkout_finish);
        deliverOrderOperateStatusCheck(orderItem, operateStatus, OrderOperateStatus.deliver_checkout_finish, normalStock);
        // in_product_area
        orderOperateStatusCheck(orderItem, operateStatus, OrderOperateStatus.stock_in_product_area);
        deliverOrderOperateStatusCheck(orderItem, operateStatus, OrderOperateStatus.deliver_in_product_area, normalStock);
        // in_checkout_area
        orderOperateStatusCheck(orderItem, operateStatus, OrderOperateStatus.stock_in_checkout_area);
        deliverOrderOperateStatusCheck(orderItem, operateStatus, OrderOperateStatus.deliver_in_checkout_area, normalStock);
        // put_away_finish
        orderOperateStatusCheck(orderItem, operateStatus, OrderOperateStatus.deliver_put_away_finish);
        orderOperateStatusCheck(orderItem, operateStatus, OrderOperateStatus.stock_put_away_finish);
    }

    private void orderFinishCheck(CustomerPlatformOrderItemRespDTO orderItem, OrderOperateStatus operateStatus, Boolean normal, Boolean normalStock) {
        if (operateStatus.equals(OrderOperateStatus.deliver_order_finish)) {
            if (normal && normalStock) {
                if (orderItem.getProductType().equals(ProductType.COMB.getType())) {
                    boolean result = orderItem.getCombinationOrderItemList().stream().allMatch(itemStatus -> Integer.valueOf(itemStatus.getOrderItemStatus()).equals(OrderDataStatus.order_item_status_eight.getStatus()));
                    Assert.assertTrue(result, "直发下单完成-普通商品有库存，验证组合商品状态-" + OrderDataStatus.order_item_status_eight.getDescription());
                } else {
                    boolean result = orderItem.getOrderItemStatusList().stream().anyMatch(itemStatus -> itemStatus.getOrderItemStatus().equals(OrderDataStatus.order_item_status_eight.getStatus()));
                    Assert.assertTrue(result, "直发下单完成-普通商品有库存，验证OEM+普通商品状态-" + OrderDataStatus.order_item_status_eight.getDescription());
                }
            }
            if (normal && !normalStock) {
                if (orderItem.getProductType().equals(ProductType.COMB.getType())) {
                    boolean result = orderItem.getCombinationOrderItemList().stream().allMatch(itemStatus -> Integer.valueOf(itemStatus.getOrderItemStatus()).equals(OrderDataStatus.order_item_status_seven.getStatus()));
                    Assert.assertTrue(result, "直发下单完成-普通商品无库存，验证组合商品状态-" + OrderDataStatus.order_item_status_seven.getDescription());
                } else if (orderItem.getProductType().equals(ProductType.NORMAL.getType())) {
                    boolean result = orderItem.getOrderItemStatusList().stream().anyMatch(itemStatus -> itemStatus.getOrderItemStatus().equals(OrderDataStatus.order_item_status_one.getStatus()));
                    Assert.assertTrue(result, "直发下单完成-普通商品无库存，验证普通商品状态-" + OrderDataStatus.order_item_status_one.getDescription());
                } else {
                    boolean result = orderItem.getOrderItemStatusList().stream().anyMatch(itemStatus -> itemStatus.getOrderItemStatus().equals(OrderDataStatus.order_item_status_seven.getStatus()));
                    Assert.assertTrue(result, "直发下单完成-普通商品无库存，验证OEM商品状态-" + OrderDataStatus.order_item_status_seven.getDescription());
                }
            }
            if (!normal) {
                if (orderItem.getProductType().equals(ProductType.COMB.getType())) {
                    boolean result = orderItem.getCombinationOrderItemList().stream().allMatch(itemStatus -> Integer.valueOf(itemStatus.getOrderItemStatus()).equals(OrderDataStatus.order_item_status_eight.getStatus()));
                    Assert.assertTrue(result, "直发下单完成-普通商品无库存，验证组合商品状态-" + OrderDataStatus.order_item_status_eight.getDescription());
                } else {
                    boolean result = orderItem.getOrderItemStatusList().stream().anyMatch(itemStatus -> itemStatus.getOrderItemStatus().equals(OrderDataStatus.order_item_status_eight.getStatus()));
                    Assert.assertTrue(result, "直发下单完成-普通商品无库存，验证OEM商品状态-" + OrderDataStatus.order_item_status_eight.getDescription());
                }
            }
        }
        if (operateStatus.equals(OrderOperateStatus.stock_order_finish)) {
            if (orderItem.getProductType().equals(ProductType.COMB.getType())) {
                orderItem.getCombinationOrderItemList().forEach(itemStatus -> {
                    if (itemStatus.getProductType().equals(ProductType.OEM.getType())) {
                        Assert.assertEquals(Integer.valueOf(itemStatus.getOrderItemStatus()), OrderDataStatus.order_item_status_two.getStatus(), "囤货下单完成，验证组合OEM商品状态");
                    } else {
                        Assert.assertEquals(Integer.valueOf(itemStatus.getOrderItemStatus()), OrderDataStatus.order_item_status_one.getStatus(), "囤货下单完成，验证组合普通商品状态");
                    }
                });
            } else if (orderItem.getProductType().equals(ProductType.NORMAL.getType())) {
                boolean result = orderItem.getOrderItemStatusList().stream().anyMatch(itemStatus -> itemStatus.getOrderItemStatus().equals(OrderDataStatus.order_item_status_one.getStatus()));
                Assert.assertTrue(result, "囤货下单完成，验证普通商品状态-" + OrderDataStatus.order_item_status_one.getDescription());
            } else {
                boolean result = orderItem.getOrderItemStatusList().stream().anyMatch(itemStatus -> itemStatus.getOrderItemStatus().equals(OrderDataStatus.order_item_status_two.getStatus()));
                Assert.assertTrue(result, "囤货下单完成，验证OEM商品状态-" + OrderDataStatus.order_item_status_two.getDescription());
            }
        }
    }

    private void orderOperateStatusCheck(CustomerPlatformOrderItemRespDTO orderItem, OrderOperateStatus actualStatus, OrderOperateStatus expectStatus) {
        if (actualStatus.equals(expectStatus)) {
            if (orderItem.getProductType().equals(ProductType.COMB.getType())) {
                boolean result = orderItem.getCombinationOrderItemList().stream().allMatch(itemStatus -> Integer.valueOf(itemStatus.getOrderItemStatus()).equals(expectStatus.getStatus().getStatus()));
                Assert.assertTrue(result, expectStatus.getName() + "-组合商品-" + expectStatus.getStatus().getDescription());
            } else {
                boolean result = orderItem.getOrderItemStatusList().stream().allMatch(itemStatus -> itemStatus.getOrderItemStatus().equals(expectStatus.getStatus().getStatus()));
                Assert.assertTrue(result, expectStatus.getName() + "-普通+OEM商品-" + expectStatus.getStatus().getDescription());
            }
        }
    }

    private void deliverOrderOperateStatusCheck(CustomerPlatformOrderItemRespDTO orderItem, OrderOperateStatus actualStatus, OrderOperateStatus expectStatus, Boolean normal1) {
        if (actualStatus.equals(expectStatus)) {
            if (normal1) {
                if (orderItem.getProductType().equals(ProductType.COMB.getType())) {
                    boolean result = orderItem.getCombinationOrderItemList().stream().allMatch(itemStatus -> Integer.valueOf(itemStatus.getOrderItemStatus()).equals(OrderDataStatus.order_item_status_eight.getStatus()));
                    Assert.assertTrue(result, expectStatus.getName() + "-普通商品有库存-组合商品-" + expectStatus.getStatus().getDescription());
                } else {
                    boolean result = orderItem.getOrderItemStatusList().stream().allMatch(itemStatus -> itemStatus.getOrderItemStatus().equals(OrderDataStatus.order_item_status_eight.getStatus()));
                    Assert.assertTrue(result, expectStatus.getName() + "-普通商品有库存-+OEM商品-" + expectStatus.getStatus().getDescription());
                }
            } else {
                if (orderItem.getProductType().equals(ProductType.COMB.getType())) {
                    boolean result = orderItem.getCombinationOrderItemList().stream().allMatch(itemStatus -> Integer.valueOf(itemStatus.getOrderItemStatus()).equals(OrderDataStatus.order_item_status_seven.getStatus()));
                    Assert.assertTrue(result, expectStatus.getName() + "-普通商品无库存-组合商品-" + expectStatus.getStatus().getDescription());
                } else if (orderItem.getProductType().equals(ProductType.NORMAL.getType())) {
                    boolean result = orderItem.getOrderItemStatusList().stream().allMatch(itemStatus -> itemStatus.getOrderItemStatus().equals(expectStatus.getStatus().getStatus()));
                    Assert.assertTrue(result, expectStatus.getName() + "-普通商品无库存-普通商品-" + expectStatus.getStatus().getDescription());
                } else {
                    boolean result = orderItem.getOrderItemStatusList().stream().allMatch(itemStatus -> itemStatus.getOrderItemStatus().equals(OrderDataStatus.order_item_status_seven.getStatus()));
                    Assert.assertTrue(result, expectStatus.getName() + "-普通商品无库存-OEM商品-" + expectStatus.getStatus().getDescription());
                }
            }
        }
    }

    /**
     * 校验订单商品状态
     *
     * @param clientLoginDTO  登录数据
     * @param platformOrderNo 订单号
     * @param productSku      订单商品sku
     * @param node            1 下单完成，2 分单完成，3 采购完成，4 检品完成，5 入成品区，6 入质检区，7 上架完成，
     * @return
     */
    @SneakyThrows
    public String orderProductStatusAssert(ClientLoginDTO clientLoginDTO, String platformOrderNo, String productSku, Integer node) {
        Thread.sleep(10000);
        String clientOrderList = orderService.clientOrderList(clientLoginDTO, platformOrderNo);
        String platformOrderId = JsonUtil.extractString(clientOrderList, "data.records[0].platformOrderId");
        // 获取订单详情
        Map<String, String> params = new HashMap<>();
        params.put("platformOrderId", platformOrderId);
        String orderDetail = new HttpClientUtil(Headers.setClientHeader(clientLoginDTO))
                .doGet(OrderAPI.ORDER_DETAIL.getApi(), params);

        JSONArray data = JsonUtil.extractJSONArray(orderDetail, "data.platformOrderItemList");

        // 订单商品id为空字符串时，按商品状态全部一致处理
        if (productSku == null || productSku.equals("")) {
            for (Object ob : data) {
                JSONArray orderItemStatusList = ((JSONObject) ob).getJSONArray("orderItemStatusList");
                Integer sellQuantity = ((JSONObject) ob).getInteger("sellQuantity");
                Integer productType = ((JSONObject) ob).getInteger("productType");
                // 判断商品类型：productType: 1 普通商品，2 OEM商品，3 组合商品
                if (productType == 1) {
                    if (orderItemStatusList.size() == 1) {
                        productTypeAssert1(node, orderItemStatusList, sellQuantity);
                    } else {
                        return "订单下的单个sku商品状态有多个！！！！";
                    }
                }
                if (productType == 2) {
                    if (orderItemStatusList.size() == 1) {
                        productTypeAssert2(node, orderItemStatusList, sellQuantity);
                    } else {
                        return "订单下的单个sku商品状态有多个！！！！";
                    }
                }
                if (productType == 3) {
                    JSONArray combinationOrderItemList = ((JSONObject) ob).getJSONArray("combinationOrderItemList");
                    productTypeAssert3(node, combinationOrderItemList);
                }
            }
        }
        return orderDetail;
    }

    /**
     * 普通商品状态值校验
     *
     * @param node
     * @param orderItemStatusList
     * @param sellQuantity
     */
    private void productTypeAssert1(Integer node, JSONArray orderItemStatusList, Integer sellQuantity) {
        Integer orderItemStatus = orderItemStatusList.getJSONObject(0).getInteger("orderItemStatus");
        Integer commodityQuantity = orderItemStatusList.getJSONObject(0).getInteger("commodityQuantity");
        switch (node) {
            case 1:  // 校验下单成功：校验商品状态：待采购；校验状态对应的数量
                Assert.assertEquals(orderItemStatus, OrderDataStatus.order_item_status_one.getStatus());
                Assert.assertEquals(sellQuantity, commodityQuantity);
                break;
            case 2:  // 校验分单成功：校验商品状态：待采购；校验状态对应的数量
                Assert.assertEquals(orderItemStatus, OrderDataStatus.order_item_status_two.getStatus());
                Assert.assertEquals(sellQuantity, commodityQuantity);
                break;
            case 3:  // 校验采购完成：商品状态，数量
                Assert.assertEquals(orderItemStatus, OrderDataStatus.order_item_status_four.getStatus());
                Assert.assertEquals(sellQuantity, commodityQuantity);
                break;
            case 4:
            case 5: // 校验检品完成,入成品区完成：商品状态，数量
                Assert.assertEquals(orderItemStatus, OrderDataStatus.order_item_status_five.getStatus());
                Assert.assertEquals(sellQuantity, commodityQuantity);
                break;
            case 6:  // 校验入质检区：商品状态，数量
                Assert.assertEquals(orderItemStatus, OrderDataStatus.order_item_status_six.getStatus());
                Assert.assertEquals(sellQuantity, commodityQuantity);
                break;
            case 7:  // 校验上架完成：商品状态，数量
                Assert.assertEquals(orderItemStatus, OrderDataStatus.order_item_status_seven.getStatus());
                Assert.assertEquals(sellQuantity, commodityQuantity);
                break;
            default:  // 输入的操作节点不存在
                LogUtil.warn(MSG + node.toString());
                break;
        }

    }

    /**
     * oem商品状态值校验
     *
     * @param node
     * @param orderItemStatusList
     * @param sellQuantity
     */
    private void productTypeAssert2(Integer node, JSONArray orderItemStatusList, Integer sellQuantity) {
        Integer orderItemStatus = orderItemStatusList.getJSONObject(0).getInteger("orderItemStatus");
        Integer commodityQuantity = orderItemStatusList.getJSONObject(0).getInteger("commodityQuantity");
        switch (node) {
            case 1:
            case 2:  // 校验下单成功,分单成功：校验商品状态：待采购；校验状态对应的数量
                Assert.assertEquals(orderItemStatus, OrderDataStatus.order_item_status_two.getStatus());
                Assert.assertEquals(sellQuantity, commodityQuantity);
                break;
            case 3:  // 校验采购完成：商品状态，数量
                Assert.assertEquals(orderItemStatus, OrderDataStatus.order_item_status_four.getStatus());
                Assert.assertEquals(sellQuantity, commodityQuantity);
                break;
            case 4:
            case 5: // 校验检品完成,入成品区完成：商品状态，数量
                Assert.assertEquals(orderItemStatus, OrderDataStatus.order_item_status_five.getStatus());
                Assert.assertEquals(sellQuantity, commodityQuantity);
                break;
            case 6:  // 校验入质检区：商品状态，数量
                Assert.assertEquals(orderItemStatus, OrderDataStatus.order_item_status_six.getStatus());
                Assert.assertEquals(sellQuantity, commodityQuantity);
                break;
            case 7:  // 校验上架完成：商品状态，数量
                Assert.assertEquals(orderItemStatus, OrderDataStatus.order_item_status_seven.getStatus());
                Assert.assertEquals(sellQuantity, commodityQuantity);
                break;
            default:  // 输入的操作节点不存在
                LogUtil.warn(MSG + node.toString());
                break;
        }
    }

    /**
     * 组合商品子商品状态校验
     *
     * @param node
     * @param combinationOrderItemList
     */
    private void productTypeAssert3(Integer node, JSONArray combinationOrderItemList) {

        for (Object o : combinationOrderItemList) {
            Integer orderItemStatus = Integer.parseInt(((JSONObject) o).getString("orderItemStatus"));
            String orderQuantity = ((JSONObject) o).getString("orderQuantity");
            String sellQuantity = ((JSONObject) o).getString("sellQuantity");

            switch (node) {
                case 1:  // 校验下单成功：校验商品状态：待采购；校验状态对应的数量
                    Assert.assertEquals(orderItemStatus, OrderDataStatus.order_item_status_one.getStatus());
                    Assert.assertEquals(sellQuantity, orderQuantity);
                    break;
                case 2:  // 校验分单成功：商品状态，数量
                    Assert.assertEquals(orderItemStatus, OrderDataStatus.order_item_status_two.getStatus());
                    Assert.assertEquals(sellQuantity, orderQuantity);
                    break;
                case 3:  // 校验采购完成：商品状态，数量
                    Assert.assertEquals(orderItemStatus, OrderDataStatus.order_item_status_four.getStatus());
                    Assert.assertEquals(sellQuantity, orderQuantity);
                    break;
                case 5: // 校验检品完成,入成品区完成：商品状态，数量
                    Assert.assertEquals(orderItemStatus, OrderDataStatus.order_item_status_five.getStatus());
                    Assert.assertEquals(sellQuantity, orderQuantity);
                    break;
                case 6:  // 校验入质检区：商品状态，数量
                    Assert.assertEquals(orderItemStatus, OrderDataStatus.order_item_status_six.getStatus());
                    Assert.assertEquals(sellQuantity, orderQuantity);
                    break;
                case 7:  // 校验上架完成：商品状态，数量
                    Assert.assertEquals(orderItemStatus, OrderDataStatus.order_item_status_seven.getStatus());
                    Assert.assertEquals(sellQuantity, orderQuantity);
                    break;
                default:  // 输入的操作节点不存在
                    LogUtil.warn(MSG + node.toString());
                    break;
            }
        }
    }

}
